package com.heima.leetcode.practice;

/**
 * @author 勾新杰
 * @version 1.0
 * @description: leetcode 12. 整数转罗马数字
 * @date 2025/3/16 23:35
 */
public class E12 {

    /**
     * 数字
     */
    private final int[] values = {1000, 900, 500, 400, 100, 90, 50, 40, 10, 9, 5, 4, 1};

    /**
     * 数字对应的罗马数字
     */
    private final String[] symbols = {"M", "CM", "D", "CD", "C", "XC", "L", "XL", "X", "IX", "V", "IV", "I"};

    /**
     * <h3>方法一：贪心算法，每次选最大的</h3>
     * @param num 整数
     * @return 罗马数字
     */
    public String intToRoman(int num) {
        StringBuilder builder = new StringBuilder();
        // 贪心算法，每次选最大的权重
        for (int i = 0; i < values.length; i++) {
            while(num >= values[i]){
                builder.append(symbols[i]);
                num -= values[i];
            }
        }
        return builder.toString();
    }
}
